<template>
  <div>
    <!-- 面包屑导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <div id="main"></div>
    </el-card>
  </div>
</template>

<script>
// 导入echarts
import * as echarts from 'echarts'

export default {
  data() {
    return {
      option: null
    }
  },
  methods: {
    // mychars被写死了真是情况应该是能响应的
    async getEcharsOption() {
      const res = await this.$http.get('reports/type/1')
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      res.data.title = {
        text: '用户来源'
      }
      res.data.tooltip = {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          label: {
            backgroundColor: '#E9EEF3'
          }
        }
      }
      res.data.grid = {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      }
      res.data.xAxis[0].boundaryGap = false
      res.data.yAxis[0].type = 'value'
      res.data.color = ['#db7a69', '#697a86', '#8ab7c1', '#e4ab8f', '#acd2c3']
      this.option = res.data
      // 实例化echarts
      var myChart = echarts.init(document.getElementById('main'))
      // 导入echarts配置对象
      var option = this.option

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    }
  },
  mounted() {
    // 获取option配置项,配置echars
    this.getEcharsOption()
  }
}
</script>

<style lang="less" scoped>
#main {
  width: 800px;
  height: 600px;
}
</style>
